import React, { useState, useEffect } from 'react';
import { connect } from 'dva';
import { useUpdateEffect } from '@umijs/hooks';
import { Tooltip, Row, Col, Card, Form, Input, Button, Modal, Tree } from 'antd';
import dynamic from 'umi/dynamic';
import LoadingComponent from '@/components/PageLoading/index';
import SlickTable from '@/components/SlickTable';
import useSlickTable from '@/hooks/useSlickTable';
import request from '@/utils/request';

const { DirectoryTree } = Tree;

const namespace = 'flowTacheConfig';

// 判断空对象
const isEmptyObject = obj => {
  if (Object.keys(obj).length === 0) {
    return true;
  }
  return false;
};

function TacheCatalogTree(props) {
  const [treeData, setTreeDate] = useState([]);

  useEffect(() => {
    request('pmc/pms/tacheCatalog/queryTreeList', {
      method: 'GET',
      data: {
        tenantId: 'BPC',
      },
    }).then(res => {
      if (res && res.success === true) {
        setTreeDate(res.data);
      } else {
        // Modal.error({title: "提交失败", content: (res.resultMsg)});
      }
    });
  }, []);

  // 通过dva存当前需要传递的数据
  const saveSelectCatalog = params => {
    const { dispatch } = props;
    dispatch({
      type: `${namespace}/saveSelectCatalog`,
      payload: params,
    });
  };

  const onSelect = (record, e) => {
    console.log(record);
    saveSelectCatalog(record);
  };

  const onExpand = record => {};

  return (
    <DirectoryTree
      multiple
      defaultExpandAll
      onSelect={onSelect}
      onExpand={onExpand}
      treeData={treeData}
    />
  );
}

export default connect(({ flowTacheConfig, setting }) => ({
  selectRecord: flowTacheConfig.selectRecord,
  size: setting.size,
}))(Form.create()(TacheCatalogTree));
